package br.edu.infnet.avaliacao.model;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "papel", catalog = "avaliacao")
public class Papel implements java.io.Serializable, Comparable<Papel> {

	private static final long serialVersionUID = -754386131809007576L;
	private String papel;
	private String descricao;
	private Set<Usuario> usuarios = new HashSet<Usuario>(0);

	public Papel() {
	}

	public Papel(String descricao, Set<Usuario> usuarios) {
		this.descricao = descricao;
		this.usuarios = usuarios;
	}
	
	@Id
	@Column(name = "papel", length = 50)
	public String getPapel() {
		return this.papel;
	}

	public void setPapel(String papel) {
		this.papel = papel;
	}

	@Column(name = "descricao", length = 50)
	public String getDescricao() {
		return this.descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "usuario_papel", catalog = "avaliacao", joinColumns = { @JoinColumn(name = "papel", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "username", nullable = false, updatable = false) })
	public Set<Usuario> getUsuarios() {
		return this.usuarios;
	}

	public void setUsuarios(Set<Usuario> usuarios) {
		this.usuarios = usuarios;
	}
	
	@Override
	public boolean equals(Object o) {
		if(!(o instanceof Papel)){
			return false;
		}
		Papel papel = (Papel) o;
		return this.getPapel().equals(papel.getPapel());
	}

	@Override
	public int compareTo(Papel papel) {
		return this.getPapel().compareTo(papel.getPapel());
	}

}
